{% extends 'base.html' %}

{% block title %}个人资料 - Will's Blog{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-8 mx-auto">
        <div class="card">
            <div class="card-header">
                <h4 class="mb-0">个人资料</h4>
            </div>
            <div class="card-body">
                <div class="row mb-4">
                    <div class="col-md-4 text-center">
                        <div class="avatar-container mb-3">
                            <img src=""
                                 class="rounded-circle img-fluid" alt="{{ current_user.username }}">
                        </div>
                        <h5>{{ current_user.name or current_user.username }}</h5>
                        <p class="text-muted">{{ current_user.email }}</p>
                        <p><small>注册于 {{ current_user.member_since.strftime('%Y-%m-%d') }}</small></p>
                        <a href="{{ url_for('auth.change_password') }}" class="btn btn-outline-secondary btn-sm">修改密码</a>
                    </div>
                    
                    <div class="col-md-8">
                        <form method="post">
                            {{ form.hidden_tag() }}
                            
                            <div class="mb-3">
                                {{ form.name.label(class="form-label") }}
                                {{ form.name(class="form-control") }}
                                {% if form.name.errors %}
                                    <div class="invalid-feedback d-block">
                                        {% for error in form.name.errors %}
                                            {{ error }}
                                        {% endfor %}
                                    </div>
                                {% endif %}
                            </div>
                            
                            <div class="mb-3">
                                {{ form.about_me.label(class="form-label") }}
                                {{ form.about_me(class="form-control", rows=5) }}
                                {% if form.about_me.errors %}
                                    <div class="invalid-feedback d-block">
                                        {% for error in form.about_me.errors %}
                                            {{ error }}
                                        {% endfor %}
                                    </div>
                                {% endif %}
                            </div>
                            
                            <div class="d-grid gap-2">
                                {{ form.submit(class="btn btn-primary") }}
                            </div>
                        </form>
                    </div>
                </div>
                
                {% if current_user.is_admin %}
                <div class="alert alert-info">
                    <i class="bi bi-shield-check"></i> 您是管理员，可以访问 <a href="{{ url_for('admin.index') }}">管理后台</a>
                </div>
                {% endif %}
                
                <div class="user-stats mt-4">
                    <h5>统计信息</h5>
                    <div class="row text-center">
                        <div class="col-4">
                            <div class="stat-item">
                                <h3>{{ current_user.posts.count() }}</h3>
                                <p>文章</p>
                            </div>
                        </div>
                        <div class="col-4">
                            <div class="stat-item">
                                <h3>{{ current_user.comments.count() }}</h3>
                                <p>评论</p>
                            </div>
                        </div>
                        <div class="col-4">
                            <div class="stat-item">
                                <h3>{{ current_user.last_seen.strftime('%Y-%m-%d') }}</h3>
                                <p>最后登录</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}